package com.ibeetl.cms.service;

import java.util.Date;
import java.util.List;

import com.ibeetl.cms.entity.IndustrialTalents;
import org.apache.poi.ss.formula.functions.T;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ibeetl.admin.core.util.PlatformException;

import com.ibeetl.cms.dao.EssentialInformationDao;
import com.ibeetl.cms.entity.EssentialInformation;
import com.ibeetl.admin.core.service.BaseService;

/**
 * EssentialInformation Service
 */

@Service
@Transactional
public class EssentialInformationService extends BaseService<EssentialInformation>{

    @Autowired
    private EssentialInformationDao essentialInformationDao;

    public PageQuery<EssentialInformation>queryByCondition(PageQuery query){
        PageQuery ret =  essentialInformationDao.queryByCondition(query);
        queryListAfter(ret.getList());
        return ret;
    }

    public void batchDelEssentialInformation(List<Long> ids){
        try {
            essentialInformationDao.batchDelEssentialInformationByIds(ids);
        } catch (Exception e) {
            throw new PlatformException("批量删除EssentialInformation失败", e);
        }
    }

    /**
     * 根据用户id查询个人基本信息
     * @param userid
     * @return
     */
    public EssentialInformation finduserid(long userid){
        EssentialInformation essentialInformation= essentialInformationDao.finduserid(userid);
        return essentialInformation;
    }

    /**
     * 根据证件号码查询用户id
     * @param identificationNumber
     * @return
     */
    public Integer findorgUserId(String identificationNumber){
        return  essentialInformationDao.findorgUserId(identificationNumber);
    }

    //根据申报名查出待上报的申报
    public int ToUpdateReported(String name, String sex, Date birthday, String nation, String politicalOutlook,
                                String maritalStatus, String nativePlace, String mailBox, String contactNumber,
                                String phoneNumber, String idType, String identificationNumber,
                                String accountOpeningBank, String bankCardNumber, String graduateSchool,
                                String major, String education, String academicDegree
                                , String currentWorkingEnterprise, String position, String majorAchievements, String declarationType, Integer userId){
        return essentialInformationDao.ToUpdateReported(name,sex,birthday,nation,politicalOutlook,
                maritalStatus,nativePlace,mailBox,contactNumber,
                phoneNumber,idType,identificationNumber,
                accountOpeningBank,bankCardNumber, graduateSchool,
                major,education,academicDegree
                ,currentWorkingEnterprise,position,majorAchievements,declarationType,userId);
    }
    //根据user_id修改基本信息的证件类型和号码(关键信息)
    public boolean updateEssentialInformation(Integer userId,String idType,String identificationNumber){
       return essentialInformationDao.updateEssentialInformation(userId,idType,identificationNumber)>0;
    }

    //企业信息名变跟时修改其员工的现工作企业名(根据user_id)
    public boolean updateWorkingName(Integer companyId,String workingName){
        return essentialInformationDao.updateWorkingName(companyId,workingName)>0;
    }
}